<template>
  <div>
    <!-- 定义面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-book :to="{ path: '/home' }">首页</el-breadcrumb-book>
      <el-breadcrumb-book>{{"->"}}图书管理</el-breadcrumb-book>
      <el-breadcrumb-book>{{"->"}}图书举报</el-breadcrumb-book>
    </el-breadcrumb>

    <!-- 定义卡片 -->
    <el-card class="box-card">

      <!-- 定义第一行数据 -->
      <el-row :gutter="20">
        <el-col :span="8">
          <el-input placeholder="请输入内容" v-model="queryBookInfo.query" clearable @clear="getBookReportList">
            <el-button slot="append" icon="el-icon-search" @click="getBookReportList"></el-button>
          </el-input>
        </el-col>

      </el-row>
      <el-table :data="bookReportList" style="width: 100%" stripe border>

        <el-table-column type="index" align="center" label="序号" width="100px">
        </el-table-column>

        <el-table-column prop="userId" align="center" label="举报用户ID" width="100px">
        </el-table-column>

        <el-table-column prop="bookId" align="center" label="举报图书ID" width="100px">
        </el-table-column>

        <el-table-column prop="reason" align="center" label="举报理由" width="100px">
        </el-table-column>

        <el-table-column prop="created" align="center" label="举报时间" width="200px">
          <template slot-scope="scope">
            <!-- {{scope.row.price | priceFormat}} -->
            {{scope.row.created | dateYMDHMSFormat}}
          </template>
        </el-table-column>

        <el-table-column prop="settled" align="center" label="受理状态" width="100px">
          <template slot-scope="scope">
            <el-switch v-model="scope.row.settled" active-color="#13ce66" inactive-color="#ff4949"
              @change="updateStatus(scope.row)"></el-switch>
          </template>
        </el-table-column>

      </el-table>

      <!-- 定义分页插件-->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryBookInfo.pageNum" :page-sizes="[1, 5, 10, 20]" :page-size="queryBookInfo.pageSize"
        layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </el-card>

  </div>
</template>

<script>
  export default {
    data() {
      return {
        //1.定义商品列表信息
        bookReportList: [],
        bookReport: {
          id: '',
          userId:'',
          bookId:'',
          reason:'',
          settled:'',
        },
        //2.定义分页对象
        queryBookInfo: {
          query: '', //定义查询参数
          pageNum: 1,
          pageSize: 10
        },
        total: 0,
      }
    },
    created() {
      //1.获取商品列表数据
      this.getBookReportList()
    },
    methods: {
      //实现审核书籍信息分页查询
      async getBookReportList() {
        const {
          data: result
        } = await this.$http.get("/bookReport/getBookReportList", {
          params: this.queryBookInfo
        })
        if (result.status !== 200) return this.$message.error("书籍列表查询失败")
        this.bookReportList = result.data.rows
        this.total = result.data.total
      },
      async updateStatus(bookReport) {
        const {
          data: result
        } = await this.$http.put(`/bookReport/updateBookReportStatus/${bookReport.id}/${bookReport.settled}`)
        if (result.status !== 200) {
          return this.$message.error("更新状态失败")
        }else{
          this.$message.success("已处理")
        }
      },

      //条数变化时 调用
      handleSizeChange(size) {
        this.queryBookInfo.pageSize = size
        this.getBookReportList()
      },
      //页码值变化时 调用
      handleCurrentChange(current) {
        this.queryBookInfo.pageNum = current
        this.getBookReportList()
      },

    //利用钩子函数实现数据查询
    mounted(){
      this.getBookReportList()
    },
  },
}
</script>
<!-- 防止组件样式冲突 -->
<style lang="less" scoped>

</style>
